<?

	$dir = pathinfo($_SERVER['SCRIPT_FILENAME']); 

	if (ini_set("include_path",ini_get("include_path").((strtoupper(PHP_OS) == "LINUX") ? ":" : ";").$dir['dirname']) === false) {
		echo "ERROR: Definicion en el include_path";
		exit;
	}

	include('adodb/adodb.inc.php');
	include_once('adodb/adodb-pager.inc.php');
    include_once('conf/dbconn_param.php');
	
	
	$db = ADONewConnection($dbdriver);
	$db->Connect($server, $user, $password, $database);
	$db->SetFetchMode(ADODB_FETCH_ASSOC);

    $db->debug = false;
	
	$sql = 'select * from bodega';
    $rs = $db->Execute($sql);
    $temas = $rs->GetRows();
	
	$db->Close();
	
	
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Bodegas</title>

<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="http://www.datatables.net/rss.xml">

<style type="text/css" media="screen">
	@import "media/css/demo_page.css";
	@import "media/css/demo_table.css";
	@import "media/css/site_jui.css";
	@import "media/css/demo_table_jui.css";
	@import "media/css/themes/base/jquery-ui.css";
	@import "media/css/themes/smoothness/jquery-ui-1.7.2.custom.css";
	@import "media/css/TableTools.css";
	/*
	 * Override styles needed due to the mix of three different CSS sources! For proper examples
	 * please see the themes example in the 'Examples' section of this site
	 */
	
	.dataTables_info { padding-top: 0; }
	.dataTables_paginate { padding-top: 0; }
	.css_right { float: right; }
	#example_wrapper .fg-toolbar { font-size: 0.8em }
	#theme_links span { float: left; padding: 2px 10px; }
</style>

<script type="text/javascript" src="media/js/complete.js"></script>
<script src="media/js/jquery-1.6.2.js" type="text/javascript"></script>
<script src="media/js/jquery.dataTables.min.js" type="text/javascript"></script>
<script type="text/javascript" src="media/js/jquery.dataTables.editable.js"></script>
<script src="media/js/jquery.jeditable.js" type="text/javascript"></script>
<script src="media/js/jquery-ui.js" type="text/javascript"></script>
<script src="media/js/jquery.validate.js" type="text/javascript"></script>
<script src="media/js/pagination.extra.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8" src="media/js/ZeroClipboard.js"></script>
<script type="text/javascript" charset="utf-8" src="media/js/TableTools.js"></script>

<script src="media/jAlert/jquery.alerts.js" type="text/javascript"></script>
<link href="media/jAlert/jquery.alerts.css" rel="stylesheet" type="text/css" />

 <script language="JavaScript" type="text/javascript">
 
 
 	 $(document).ready(function () {
		// Lenar un combo dinamico usando ajax y php
		$('#tema').change(function(event){
			  var varTema = $(this).val();
			  $("#cargando").css("display", "inline");
			  $("#subtema").load("php/getSubtemaCombo.php",{tema : varTema}, function(){
         			$("#cargando").css("display", "none");
      		   });
		  }); 
		
		   
		  $('#prueba').click(function(event){
			  window.location.reload();						 
		  });
		  
		  		  
		  var oTable = $('#example').dataTable({ 
				 bJQueryUI: true,
				 "sPaginationType": "four_button", 
				 "oLanguage": {
				     "sUrl": ""
			      },
				  "bProcessing": true,
				  "aoColumns": [ 
						{ "bVisible": true, "asSorting": [ "asc" ]  },
						{},{}
				  ],	

				  'sAjaxSource': "php/GetDataBodega.php",
				  "sDom": 'T<"clear">lfrtip',
				  "oTableTools": {
					  "sSwfPath": "media/swf/copy_cvs_xls_pdf.swf"
				  }
			   }).makeEditable({
				   sUpdateURL: "php/UpdateDataBodega.php",
				   
				   "aoColumns": [
                    					{
                						cssclass:"required"
                    					},
                    					{
                						cssclass:"required"
                    					},
                    					{
                						cssclass:"required"
                    					},
                    								
								],
				    fnShowError: function (message, action) {
                        switch (action) {
                            case "update":
                                jAlert(message, "ERROR en Actualización");
                                break;
                            case "delete":
                                jAlert(message, "ERROR en Eliminación de registro");
                                break;
                            case "add":
                                $("#lblAddError").html(message);
                                $("#lblAddError").show();
                                break;
                        }
                    },
				   
				    fnStartProcessingMode: function () {
                        $("#processing_message").dialog();
                    },
					/*
					// Opcion de validacion en el insertado
					fnOnAdding : function () {
						
						jQuery.ajax({
                              type: "POST",
                              url: "php/validar.php",
							  // Aqui paso los valores para la validacion
                              data: "datos="+$('#descripcion').val(),
                              success: function(datos){
                                  if(datos=="no mola"){
									  alert("Ha habido un error al enviar, lo sentimos. Pruebe mas tarde.");
								  }
                                  else{
									  alert("Formulario enviado correctamente!!! \n\nMuchas gracias por confiar en nosotros, atenderemos vuestra consulta lo antes posible.\n\nUn saludo.");
                                  }
                              }
                        });
						
						return false;
					},
					*/
					
					fnOnAdded : function () {
						oTable.fnReloadAjax();
					},
                    fnEndProcessingMode: function () {
                        $("#processing_message").dialog("close");
						
                    },
				    fnOnDeleting: function (tr, id, fnDeleteRow) {
                        jConfirm('\u00BF Desea eliminar el registro ' + id + ' ?', 'Confirmación de borrado', function (r) {
                            if (r) {
                                fnDeleteRow(id);
                            }
                        });
                        return false;
                    },
				   
				   
				   sAddURL: "php/AddDataBodega.php",
				   sAddHttpMethod: "GET",
				   oAddNewRowButtonOptions: {icons: {primary:'ui-icon-plus'}},
				   
				   sDeleteURL: "php/DeleteDataBodega.php",
				   sDeleteHttpMethod: "GET",
				   oDeleteRowButtonOptions: {icons: {primary:'ui-icon-trash'}},
				   
				   
				   oAddNewRowFormOptions: { 	
				                            width: '700px',
				                            title: 'Adicionar nueva bodega',
											show: "blind",
											hide: "explode",
                                            modal: true
									       },
					sAddDeleteToolbarSelector: ".dataTables_length"
					
			   	  
		  });
		  
		 $('#example tbody tr').click( function () {
 var aData = oTable.fnGetData( this );
 alert( aData[0] ); // assuming the id is in the first column
} );
		  
	  });
  </script>
  

</head>

<body>
<!--button id="btnAddNewRow">Adicionar</button-->

<div id="processing_message" style="display:none" title="Procesando ...">Espere hasta que se complete la operaci&oacute;n</div>

<div id="fw_container">
Aqui poner cualquier codigo antes de la tabla<br  />
<input type="button" id="prueba" value="Prueba" />
</div>

<form id="formAddNewRow" action="#" title="" style="width:600px;">
	<label id="lblAddError" style="display:none" class="error"></label>

	<input type="hidden" name="bodega_id" id="bodega_id" value="0" rel="0" />
    
    <label for="nombre">Nombre</label>
	<input type="text" name="nombre" class="required" id="nombre" rel="1" />
    <br/>
    <label for="codigo">Codigo</label>
    	<input type="text" name="codigo" class="required" id="codigo" rel="2" />
        <br/>
    <div id="cargando" style="display:none; color: green;">Cargando...<br  /></div>
    
</form>

<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
       <thead>
		<tr>
			<th >PK</th>
			<th>Nombre</th>
			<th>Codigo</th>
		</tr>
	</thead>
	<tfoot>
		<tr>
			<th >PK</th>
			<th>Nombre</th>
			<th>Codigo</th>
		</tr>
	</tfoot>
	<tbody>
    </tbody>
</table>

</body>
</html>
